package dao.impl;

import dao.GradeDao;
import model.Grade;
import util.DBUtils;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GradeDaoImpl extends DBUtils implements GradeDao {

    @Override
    public List<Grade> getGrades() {
        String sql = "select * from grade";
        List<Grade> list = new ArrayList<>();
        Grade grade = null;
        resultSet = query(sql);
        if (resultSet != null) {
            try {
                while (resultSet.next()) {
                    grade = new Grade();
                    grade.setGradecard(resultSet.getInt("gradecard"));
                    grade.setGradename(resultSet.getString("gradename"));
                    list.add(grade);
                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            } finally {
                closeAll();
            }
        }
        return list;
    }
}
